package com.dong.environment;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;

import java.util.HashMap;
import java.util.Map;

/**
 * description
 *
 * @author Administrator 2021/09/06 16:20
 */
public class EnvironmentTest {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = new GenericApplicationContext();

        MutablePropertySources propertySources = context.getEnvironment().getPropertySources();

        propertySources.addFirst(new MyPropertySource("myApplication",getResource()));

        ConfigurableEnvironment environment = context.getEnvironment();
        System.out.println(environment.containsProperty("user"));
    }

    private static Map<String,String> getResource(){
        Map<String,String> map = new HashMap<>();
        map.put("user","jerry");
        return map;
    }
}
